/*
 * Copyright (c) 2017. 深圳掌控网络有限公司. All rights reserved.
 */

package com.yiqi.lottery.feature.football.presenter;

import com.suozhang.framework.entity.bo.PageData;
import com.yiqi.lottery.entity.bo.BallMatchBo;
import com.yiqi.lottery.entity.bo.BallMatchBo2;
import com.yiqi.lottery.feature.football.contract.FootballContract;
import com.yiqi.lottery.feature.football.dependencies.football.DaggerFootballPresenterComponent;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * LIJUWEN
 *
 * @email yiyayiyayaoljw@gmail.com
 * @date 2017/4/11 9:31
 */
public class FootballPresenter implements FootballContract.Presenter {

    private FootballContract.View mView;

    @Inject

    FootballContract.Model mModel;


    public FootballPresenter(FootballContract.View mView) {
        this.mView = mView;
        DaggerFootballPresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }

    @Override
    public void getFootballMatchList(String label) {
        if (label.equals("hhgg")) {
            mModel.getFootballMatchList2(label).compose(mView.bindToLife()).subscribe(new Observer<PageData<BallMatchBo2>>() {
                @Override
                public void onSubscribe(Disposable d) {
                    mView.showLoading(d);
                }

                @Override
                public void onNext(PageData<BallMatchBo2> s) {
                    mView.dismissLoading();
                    mView.showFootballMatchListSuccess2(s);
                }

                @Override
                public void onError(Throwable e) {
                    mView.dismissLoading();
                    mView.showFootballMatchListError(e.getMessage());
                }

                @Override
                public void onComplete() {
                    mView.dismissLoading();
                }
            });
            return;
        }
        mModel.getFootballMatchList(label).compose(mView.bindToLife()).subscribe(new Observer<PageData<BallMatchBo>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(PageData<BallMatchBo> s) {
                mView.dismissLoading();
                mView.showFootballMatchListSuccess(s);
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showFootballMatchListError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void getFootballSFCMatchList() {
        mModel.getFootballSFC().compose(mView.bindToLife()).subscribe(new Observer<BallMatchBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(BallMatchBo s) {
                mView.dismissLoading();
                mView.showSFCMatchSuccess(s);
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showFootballMatchListError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }
}
